home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / midi / mdlbutls.lha / tsx.c < prev    next >
C/C++ Source or Header  |  1988-10-23  |  2KB  |  76 lines

  1. /* simplified transmit sys/ex file */
  2. /*    actually transmits entire contents of file, not just sys/ex */
  3.  
  4. /*
  5.     describes usage of PutMidiStream() limited buffer size and unknown
  6.     stream length.
  7. */
  8.  
  9. #include <midi/midi.h>
  10. #include <functions.h>
  11. #include <fcntl.h>
  12.  
  13. void *MidiBase;
  14.  
  15. static int fi;                /* input file descriptor */
  16. UBYTE buf[512];             /* buffer used for transfer */
  17.  
  18. main(argc,argv)
  19. char **argv;
  20. {
  21.     struct MSource *source=0;
  22.     struct MRoute *route=0;
  23.     extern short Enable_Abort;
  24.     char *fname;
  25.     long fillbuffer();
  26.  
  27.     printf ("Transmit Sys/Ex\n");
  28.     Enable_Abort = 0;            /* disable auto CTRL-C handling */
  29.  
  30.     if (argc < 2) {
  31.     printf ("usage: tsx <file>\n");
  32.     exit (1);
  33.     }
  34.  
  35.     fname = argv[1];            /* get file name */
  36.  
  37.     if (!(MidiBase = OpenLibrary (MIDINAME,MIDIVERSION))) {
  38.     printf ("can't open midi.library\n");
  39.     goto clean;
  40.     }
  41.                     /* create our source node (private) */
  42.     if (!(source = CreateMSource (NULL,NULL))) {
  43.     printf ("can't create Source\n");
  44.     goto clean;
  45.     }
  46.                     /* create our route to MidiOut (use default RouteInfo in MidiOut) */
  47.     if (!(route = MRouteSource (source, "MidiOut", NULL))) {
  48.     printf ("can't create Route (can't find MidiOut?)\n");
  49.     goto clean;
  50.     }
  51.                     /* open input file */
  52.     if ( (fi=open(fname,O_RDONLY)) == -1) {
  53.     printf ("can't open %s\n",fname);
  54.     goto clean;
  55.     }
  56.                     /* convert file to midi messages */
  57.     PutMidiStream (source,fillbuffer,buf,(long)sizeof buf,0L);
  58.  
  59. clean:
  60.     if (route) DeleteMRoute (route);
  61.     if (source) DeleteMSource (source);
  62.     if (MidiBase) CloseLibrary (MidiBase);
  63. }
  64.  
  65.  
  66.  
  67. /* fill our buffer with data from the file, called by PutMidiStream() */
  68.  
  69. static
  70. long fillbuffer()
  71. {
  72.     register int len;
  73.  
  74.     return (len = read(fi,buf,sizeof buf)) == -1 ? 0 : len;
  75. }
  76.